package com.ruoyi.system.service.impl;

import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.system.domain.zbg.AnnualCostData;
import com.ruoyi.system.domain.zbg.WarningAndExceptionData;
import com.ruoyi.system.mapper.AnnualCostDataMapper;
import com.ruoyi.system.mapper.WarningAndExceptionDataMapper;
import com.ruoyi.system.service.AnnualCostDataService;
import com.ruoyi.system.service.WarningAndExceptionDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class WarningAndExceptionDataServiceImpl  extends ServiceImpl<WarningAndExceptionDataMapper, WarningAndExceptionData> implements WarningAndExceptionDataService {
    @Autowired
    private WarningAndExceptionDataMapper warningAndExceptionDataMapper;
    @Autowired
    private AsyncService asyncService;
//使用事务确保全部插入才是成功
    @Transactional(rollbackFor = Exception.class)
    public void saveAll(List<WarningAndExceptionData> warningAndExceptionDataList) {
        warningAndExceptionDataList.forEach(warningAndExceptionData -> {
            warningAndExceptionDataMapper.insert(warningAndExceptionData);
        });
        asyncService.generateWorkOrderAsync(warningAndExceptionDataList);

    }
}